<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{:lang('list')}</legend>
    </fieldset>
    <div class="demoTable">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
        </div>
        <button class="layui-btn" id="search" data-type="reload">{:lang('search')}</button>
        <a href="{:url('index')}" class="layui-btn">显示全部</a>
        <div style="clear: both;"></div>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>

<script type="text/html" id="name">
    {{d.first_name}} {{d.last_name}}
</script>
<script type="text/html" id="action">
    <a href="{:url('admin/order/show')}?id={{d.id}}" class="layui-btn layui-btn-xs layui-btn-normal">详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <!-- <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="tuisong"  >发货</a> -->
</script>
<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        var tableIn = table.render({
            id: 'content',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            toolbar: '#topBtn',
            page: true,
            cols: [[
                //{type: "checkbox", fixed: true},
                {field: 'id', title: '{:lang("id")}', width: 80, fixed: true},
                {field: 'sn', title: '单号', width: 200},
                {field: 'order_cn', title: '状态', width: 200},
                {field: 'order_total', title: '金额', width: 100},
                {field: 'title', title: '姓名', width: 100, templet: '#name'},
                {field: 'phone', title: '电话', width: 150},
                {field: 'state', title: '州', width: 200},
                {field: 'city', title: '城市', width: 200},
                {field: 'addr1', title: '地址1', width: 200},
                {field: 'create_time', title: '{:lang("add")}{:lang("time")}', width: 180},
                {fixed:'right',width: 160, align: 'center', toolbar: '#action',title:'操作'}
            ]],
            limit: 10
        });
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            if ($.trim(key) === '') {
                layer.msg('{:lang("pleaseEnter")}关键字！', {icon: 0});
                return;
            }
            tableIn.reload({ page: {page: 1}, where: {key: key}});
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定要删除吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('listDel')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload({where:{catid:'{:input("catid")}'}});
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            if(obj.event === 'tuisong'){
                layer.confirm('您确定要推送吗', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#abc']});
                    $.post("{:url('pxPush')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload({where:{catid:'{:input("catid")}'}});
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                            tableIn.reload({where:{catid:'{:input("catid")}'}});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>